
// lodash _.chunk

const _chunk = (arr, size) => Array(Math.ceil(arr.length / size)).fill(0).map((v, i) => arr.slice(i * size, i * size + size));
console.log(_chunk([1, 2, 3, 4, 5], 2)); // [[1, 2], [3, 4], [5]]

// 计算字节

// const byteSize = str => new Blob([str]).size;
// console.log(byteSize('中文'), byteSize('en'));

// 去重
const uniqueElements = arr => [...new Set(arr)];
console.log(uniqueElements([1, 2, 3, 4, 5, 6, 7, 3, 4, 5, 2]));
console.log(uniqueElements([{ id: 1, value: 2 }, { id: 1, value: 2 }]));

const URLJoin = (...args) =>
  args
  .join('/')
  .replace(/[\/]+/g, '/')
  .replace(/^(.+):\//, '$1://')
  .replace(/^file:/, 'file:/')
  .replace(/\/(\?|&|#[^!])/g, '$1')
  .replace(/\?/g, '&')
  .replace('&', '?');
console.log(URLJoin('http://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo'));